<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Soal_model extends CI_Model {

	public function get_list(){
		$this->db->from('tbl_soal a');
		$this->db->join('ref_bab b','a.bab_id = b.bab_id','left');
		$this->db->join('ref_pelajaran c','b.bab_pel_id = c.pel_id','left');
		$this->db->join('ref_kelas d','c.pel_kelas_id = d.kelas_id','left');
		$this->db->join('ref_jenjang e','d.kelas_jenjang_id = e.jenjang_id','left');
		$this->db->group_by('b.bab_id');
		return $this->db->get();
	}

	public function get_jenjang(){
		$this->db->where('jenjang_active','yes');
		return $this->db->get('ref_jenjang');
	}

	public function get_kelas(){
		$this->db->where('kelas_active','yes');
		return $this->db->get('ref_kelas');
	}

	public function get_cat(){
		$this->db->where('pel_active','Y');
		return $this->db->get('ref_pelajaran');
	}

	public function get_bab(){
		$this->db->where('bab_active','yes');
		return $this->db->get('ref_bab');
	}

	public function get_data($id){
		$this->db->where('a.id_soal',$id);
		$this->db->from('tbl_soal a');
		$this->db->join('ref_bab b','a.bab_id = b.bab_id','left');
		$this->db->join('ref_pelajaran c','b.bab_pel_id = c.pel_id','left');
		$this->db->join('ref_kelas d','c.pel_kelas_id = d.kelas_id','left');
		$this->db->join('ref_jenjang e','d.kelas_jenjang_id = e.jenjang_id','left');
		return $this->db->get();
	}
	
	public function get_list_soal($id){
		$this->db->select('a.*,b.*,c.*,d.*,e.*');
		$this->db->from('tbl_soal a');
		$this->db->join('ref_bab b','a.bab_id = b.bab_id','left');
		$this->db->join('ref_pelajaran c','b.bab_pel_id = c.pel_id','left');
		$this->db->join('ref_kelas d','c.pel_kelas_id = d.kelas_id','left');
		$this->db->join('ref_jenjang e','d.kelas_jenjang_id = e.jenjang_id','left');
		// $this->db->group_by('b.bab_id');
		$this->db->where('a.bab_id',$id);
		return $this->db->get();
	}

	public function do_add($param = false){
		if($param){
			return $this->db->insert('tbl_soal',$param);
		}
		return false;
	}

	public function do_update($id = false,$param = false){
		if($id){
			$this->db->where('id_soal',$id);
			return $this->db->update('tbl_soal',$param);
		}
		return false;
	}

	public function do_delete($id = false){
		if($id){
			$this->db->where('id_soal',$id);
			return $this->db->delete('tbl_soal');
		}return false;
	}
}